<template>
  <div class="article">
    <!-- this.$router.back() 后退
        this.$router.forward() 前进
        this.$router.go(0) 刷新
        this.$router.go(1) 前进
        this.$router.go(-1) 后退 -->
    <!-- <van-sticky> -->
    <van-nav-bar
      fixed
      placeholder
      title="文章详情"
      left-arrow
      @click-left="$router.push($route.query.back || '/layout/home')"
    ></van-nav-bar>
    <!-- </van-sticky> -->
    <div class="main">
      <h2 class="title">{{ info.title }}</h2>
      <div class="user">
        <img class="avatar" :src="info.aut_photo" alt="" />
        <div class="info">
          <div class="name">{{ info.aut_name }}</div>
          <div class="time">{{ info.pubdate | relvTime }}</div>
        </div>
        <van-button size="small" round color="#1989fa">+ 关注</van-button>
      </div>

      <div class="content" v-html="info.content"></div>

      <van-divider>end</van-divider>
      <div class="btn">
        <van-button plain round icon="good-job-o" type="primary">
          点赞
        </van-button>
        <van-button plain round icon="delete-o" type="danger">
          不喜欢
        </van-button>
      </div>
    </div>
    <!-- 评论区域 -->
    <Comment></Comment>
    <!-- 到底部 -->
    <div class="to-bottom" @click="toBottom">到底部</div>
  </div>
</template>
<script>
import { articles } from '@/api/article'
// article.js  article.vue  package.json  article/index.js article/index.vue
import Comment from './components/comment.vue'
export default {
  components: {
    Comment
  },
  created () {
    this.getData()
  },
  data () {
    return {
      info: ''
    }
  },
  methods: {
    async getData () {
      const res = await articles(this.$route.query.id)
      this.info = res.data
      // console.log(res)
    },
    // 到底部
    toBottom () {
      window.scrollTo(0, 999999)
    }
  }
}
</script>
<style lang="less" scoped>
.main {
  padding: 0 15px;
  .title {
    padding: 10px 0;
    font-size: 24px;
  }
  .user {
    display: flex;
    align-items: center;
    .avatar {
      width: 40px;
      height: 40px;
      border-radius: 50%;
      padding-right: 10px;
    }
    .info {
      flex: 1;
      .time {
        color: #999;
      }
    }
  }
  .content {
    padding: 15px 0;
    line-break: anywhere;
  }
  .btn {
    display: flex;
    justify-content: space-around;
  }
}
::v-deep pre {
  width: 100%;
  padding: 15px;
  background-color: #000;
  color: #fff;
  overflow: auto;
  box-sizing: border-box;
}
::v-deep code {
  // code是行内元素
  display: inline-block;
  width: 100%;
  padding: 15px;
  background-color: #000;
  color: #fff;
  overflow: auto;
  box-sizing: border-box;
}
::v-deep img {
  width: 100%;
}
.to-bottom {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background-color: rgba(0, 0, 0, 0.4);
  color: #fff;
  text-align: center;
  line-height: 60px;
  position: fixed;
  right: 20px;
  bottom: 80px;
}
</style>
